<?php
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.gxgyl.com All rights reserved.

// +----------------------------------------------------------------------
// | Author: Liuyu
// +----------------------------------------------------------------------
declare (strict_types = 1);

namespace app\api\controller;

use app\api\model\Page as PageModel;
use topinyin\ChinesePinyin;

/**
 * 页面控制器
 * Class Index
 * @package app\api\controller
 */
class Page extends Controller {
	/**
	 * 页面数据
	 * @param int|null $pageId 页面ID, 不传的话默认为首页
	 * @return array|\think\response\Json
	 * @throws \cores\exception\BaseException
	 * @throws \think\db\exception\DataNotFoundException
	 * @throws \think\db\exception\DbException
	 * @throws \think\db\exception\ModelNotFoundException
	 */
	public function detail(int $pageId = null) {
		// 页面数据
		$model = new PageModel;
		$pageData = $model->getPageData($pageId);
		return $this->renderSuccess(compact('pageData'));
	}

	public function getFirstCharter(string $name) {

		$Pinyin = new ChinesePinyin();
		//带声调的汉语拼音

		// echo $Pinyin->TransformWithTone("刘钰");exit;
		//无声调的汉语拼音

		// dump($Pinyin->TransformWithoutTone("我们的歌"));
		//转成汉语拼音首字母,只包括汉字,不包含拼音

		//echo ($Pinyin->TransformUcwordsOnlyChar("刘钰"));
		//转成汉语拼音首字母,包含非汉字内容

		// dump($Pinyin->TransformUcwords("首字母和其他字符如B区32号"));

		$en = $Pinyin->TransformUcwordsOnlyChar($name);

		return $this->renderSuccess(compact('en'));
	}
}
